//访问了增强浏览器的seo,  这里用History路由，不再使用hash路由

import LayoutComponent from "@/layout/layout.vue";

import {
  createRouter,
  createWebHistory,
  type RouteRecordRaw
} from "vue-router";

//  普通路由
const constantRoutes: RouteRecordRaw[] = [
  {
    // 一级路由 访问http://localhost:xxx/ 先跳转到LayoutComponent 布局组件，访问
    path: "/",
    component: LayoutComponent,
    redirect: "/dashboard", // 二级路由
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        meta: {
          icon: "ant-design:bank-outlined",
          title: "dashboard",
          affix: true, // 固定在tagsViews中
          noCache: true //   不需要缓存
        }
      }
    ]
  },
  {
    path: "/xxxx",
    component: LayoutComponent,
    meta: {
      hidden: true, //表示要隐藏该菜单
      title: "xxxx",
      icon: "ant-design:alipay-square-filled"
    }
  },
  {
    path: "/test",
    component: LayoutComponent,
    meta: {
      icon: "ant-design:aliwangwang-filled",
      title: "test"
    },
    children: [
      {
        path: "/test/:id",
        component: () => import("@/views/test/test.vue"),
        meta: {
          hidden: true,
          icon: "ant-design:bank-outlined",
          title: "test-1111",
          affix: true, // 固定在tagsViews中
          noCache: true //   不需要缓存
        }
      }
    ]
  },
  {
    path: "/redirect",
    component: LayoutComponent,
    meta: {
      hidden: true
    },
    // 当跳转到  /redirect/a/b/c/d?query=1
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
        meta: {
          icon: "ant-design:bank-outlined",
          title: "redirect---11",
          affix: true, // 固定在tagsViews中
          noCache: true //   不需要缓存
        }
      }
    ]
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      icon: "ant-design:bank-outlined",
      title: "Login",
      hidden: false
    },
    component: () => import("@/views/login/index.vue")
  },
  {
    path: "/profile",
    component: LayoutComponent,
    name: "profile",
    redirect: "/profile/index",
    meta: {
      hidden: false
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/profile/index.vue"),
        meta: {
          icon: "ant-design:bank-outlined",
          title: "profile",
          affix: true, // 固定在tagsViews中
          noCache: true //   不需要缓存
        }
      }
    ]
  }
];

//异步路由，需要通过和后台接口进行配合
export const asyncRoutes: RouteRecordRaw[] = [
  {
    path: "/documentation",
    component: LayoutComponent,
    redirect: "/documentation/index",
    children: [
      {
        path: "index",
        name: "documentation",
        component: () => import("@/views/documentation/index.vue"),
        meta: {
          icon: "ant-design:database-filled",
          title: "documentation"
        }
      }
    ]
  },

  {
    path: "/guide",
    component: LayoutComponent,
    redirect: "/guide/index",
    meta: {
      title: "guide",
      alwaysShow: true
    },
    children: [
      {
        path: "index",
        name: "guide",
        component: () => import("@/views/guide/index.vue"),
        meta: {
          icon: "ant-design:car-twotone",
          title: "sub-guide"
        }
      }
    ]
  },
  {
    path: "/system",
    component: LayoutComponent,
    redirect: "/system/menu",
    meta: {
      icon: "ant-design:unlock-filled",
      title: "system"
      // breadcrumb: false
      // 作为父文件夹一直显示
    },
    children: [
      {
        path: "menu",
        name: "menu",
        component: () => import("@/views/system/menu/index.vue"),
        meta: {
          icon: "ant-design:unlock-filled",
          title: "menu"
        }
      },

      {
        path: "role",
        name: "role",
        component: () => import("@/views/system/role/index.vue"),
        meta: {
          icon: "ant-design:unlock-filled",
          title: "role"
        }
      },
      {
        path: "user",
        name: "user",
        component: () => import("@/views/system/user/index.vue"),
        meta: {
          icon: "ant-design:unlock-filled",
          title: "user"
        }
      }
    ]
  },

  {
    path: "/external-link",
    component: LayoutComponent,
    children: [
      {
        path: "http://www.baidu.com",
        redirect: "/",
        meta: {
          icon: "ant-design:link-outlined",
          title: "link Baidu"
        }
      }
    ]
  }
];

const routes = [...constantRoutes, ...asyncRoutes]; //普通路由和权限路由集合

const pageRouter = createRouter({
  routes,
  history: createWebHistory()
});

export { routes };

export default pageRouter;
